from django.http import HttpResponse

from execute.models import Sys_Environment, Lyzd_Interface


# 1.环境信息
def data_environment_view(environment_id):
    environment_data = Sys_Environment.objects.filter(id=environment_id).values('address', 'env_name').first()
    # {'address': 'http://127.0.0.1:9000/booklist/', 'env_name': '测试环境'}
    # 将environment_desc 修改为 environment_name
    environment_data = {
        'environment_id':environment_id,
        'environment_address':environment_data["address"],
        'environment_name':environment_data['env_name']
    }
    return environment_data

# 2.接口信息
def data_interface_view(interfaces_id):
    # 1.获取认证（0正常调接口，1加解密）
    try:
        interface_info = Lyzd_Interface.objects.get(id=interfaces_id)
        interfaces_authentication = interface_info.authentication
        print(interfaces_authentication)

        if interfaces_authentication == '0':
            interfaces_encryption_url = ''
            interfaces_decrypt_url = ''
        elif interfaces_authentication == '1':
            print("加解密接口后续补充")
            pass
        else:
            return None

    except:
        return None

    # 2.获取接口api
    testcases_api = interface_info.interface_name_en
    print(f"接口api:{testcases_api}",type(testcases_api)) # str

    # 3.获取请求方式
    testcases_method = interface_info.request_type
    print(f"接口请求方式:{testcases_method}", type(testcases_method))  # POST str

    # 4.接口名称
    testcases_name = interface_info.interface_name_zh
    print(f"接口名称:{testcases_name}", type(testcases_name)) # post请求接口名 <class 'str'>

    # 5.接口入参 pass 应该给接口入参传值了

    context = {
        "testcases_api":testcases_api,
        "interfaces_authentication":interfaces_authentication
    }
    return context